package com.hq.talk.common;

import android.content.Context;
import android.content.SharedPreferences;

import com.hq.talk.app.App;

/**
 * 数据保存
 */
public class SysSharePres {

    /**
     * sharedpreferences存储的名称
     */
    private static final String PRES_NAME = "system_share";

    private SharedPreferences mSharePres;

    /**
     * 记录app版本号
     */
    public static final String APP_VERSION = "app_version";

    /**
     * 用户是否是第一次安装APP true 是的 false不是
     */
    private static final String USER_FIRST_INSTALL = "user_first_install";

    /**
     * 用户id
     */
    private static final String USER_ID = "user_id";

    /**
     * token
     */
    private static final String USER_TOKEN = "user_token";

    /**
     * 用户是否登录 true 登录 false 未登录
     */
    private static final String USER_LOGIN = "user_login";

    /**
     * 用户头像
     */
    private static final String USER_HEAD = "user_head";

    /**
     * 用户昵称
     */
    private static final String USER_NAME = "user_name";

    /**
     * 用户签名
     */
    private static final String USER_SIGN = "user_sign";

    /**
     * 用户手机号
     */
    private static final String USER_PHONE = "user_phone";

    /**
     * 用户性别
     */
    private static final String USER_SEX = "user_sex";

    /**
     * 省
     */
    private static final String USER_PROVINCE = "user_province";
    /**
     * 市
     */
    private static final String USER_CITY = "user_city";
    /**
     * 区
     */
    private static final String USER_DISTRICT = "user_district";


    public SysSharePres() {
        mSharePres = App.getInstance().getContext().getSharedPreferences(PRES_NAME,
                Context.MODE_PRIVATE);
    }

    private static class SysSharePresHolder {

        static final SysSharePres INSTANCE = new SysSharePres();
    }

    public static SysSharePres getInstance() {
        return SysSharePresHolder.INSTANCE;
    }

    //***************************************** 处理***********************************************/
    public String getAppVersion() {
        return mSharePres.getString(APP_VERSION, "");
    }

    public void setAppVersion(String app_version) {
        mSharePres.edit().putString(APP_VERSION, app_version).commit();
    }

    public void setUserFirstInstall(boolean user_first_install) {
        mSharePres.edit().putBoolean(USER_FIRST_INSTALL, user_first_install).commit();
    }

    public boolean getUserFirstInstall() {
        return mSharePres.getBoolean(USER_FIRST_INSTALL, true);
    }

    public String getUserId() {
        return mSharePres.getString(USER_ID, "");
    }

    public void setUserId(String user_id) {
        mSharePres.edit().putString(USER_ID, user_id).commit();
    }

    public String getUserToken() {
        return mSharePres.getString(USER_TOKEN, "");
    }

    public void setUserToken(String user_token) {
        mSharePres.edit().putString(USER_TOKEN, user_token).commit();
    }

    public void setUserIsLogin(boolean user_login) {
        mSharePres.edit().putBoolean(USER_LOGIN, user_login).commit();
    }

    public boolean getUserIsLogin() {
        return mSharePres.getBoolean(USER_LOGIN, false);
    }

    public String getUserHead() {
        return mSharePres.getString(USER_HEAD, "");
    }

    public void setUserHead(String user_head) {
        mSharePres.edit().putString(USER_HEAD, user_head).commit();
    }

    public String getUserName() {
        return mSharePres.getString(USER_NAME, "");
    }

    public void setUserName(String user_name) {
        mSharePres.edit().putString(USER_NAME, user_name).commit();
    }

    public String getUserSign() {
        return mSharePres.getString(USER_SIGN, "");
    }

    public void setUserSign(String user_sign) {
        mSharePres.edit().putString(USER_SIGN, user_sign).commit();
    }

    public String getUserPhone() {
        return mSharePres.getString(USER_PHONE, "");
    }

    public void setUserPhone(String user_phone) {
        mSharePres.edit().putString(USER_PHONE, user_phone).commit();
    }

    public String getUserSex() {
        return mSharePres.getString(USER_SEX, "1");
    }

    public void setUserSex(String user_sex) {
        mSharePres.edit().putString(USER_SEX, user_sex).commit();
    }

    public String getUserProvince() {
        return mSharePres.getString(USER_PROVINCE, "");
    }

    public void setUserProvince(String user_province) {
        mSharePres.edit().putString(USER_PROVINCE, user_province).commit();
    }

    public String getUserCity() {
        return mSharePres.getString(USER_CITY, "");
    }

    public void setUserCity(String user_city) {
        mSharePres.edit().putString(USER_CITY, user_city).commit();
    }

    public String getUserDistrict() {
        return mSharePres.getString(USER_DISTRICT, "");
    }

    public void setUserDistrict(String user_district) {
        mSharePres.edit().putString(USER_DISTRICT, user_district).commit();
    }

}
